package cn.bearspark.api.service.main.impl;

import cn.bearspark.api.service.main.BookLiveService;
import cn.bearspark.api.vo.main.booklive.CancelReqVO;
import cn.bearspark.api.vo.main.booklive.StateReqVO;
import cn.bearspark.common.constant.GlobalConstant;
import cn.bearspark.common.util.ConvertBeanUtil;
import cn.bearspark.framework.web.starter.context.BSRequestContext;
import cn.bearspark.framework.web.starter.vo.ResponseVO;
import cn.bearspark.happening.dto.booklive.CancelReqDTO;
import cn.bearspark.happening.dto.booklive.StateReqDTO;
import cn.bearspark.happening.rpc.BookLiveRpc;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author f
 */
@Service
public class BookLiveServiceImpl implements BookLiveService {

    @DubboReference(check = GlobalConstant.DUBBO_CHECK)
    private BookLiveRpc bookLiveRpc;

    @Override
    public ResponseVO<Object> cancel(CancelReqVO cancelReqVO) {
        long userId = BSRequestContext.getUserId();

        CancelReqDTO cancelReqDTO = ConvertBeanUtil.convert(cancelReqVO, CancelReqDTO.class);
        cancelReqDTO.setUserId(userId);
        bookLiveRpc.cancel(cancelReqDTO);

        return ResponseVO.success();
    }

    @Override
    public ResponseVO<Object> state(StateReqVO stateReqVO) {
        long userId = BSRequestContext.getUserId();

        StateReqDTO stateReqDTO = ConvertBeanUtil.convert(stateReqVO, StateReqDTO.class);
        stateReqDTO.setUserId(userId);
        bookLiveRpc.state(stateReqDTO);

        return ResponseVO.success();
    }

}
